<?php

namespace app\api\validate;

use app\common\Status;
use think\Validate;

class UserValidate extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'    =>    ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'email'      => ['require', 'email'],
        'name'       => ['require', 'length:2,18'],
        'password'   => ['require', 'length:8,18', 'alphaNum'],
        'rePassword' => ['require', 'confirm:password'],
        'code'       => ['require', 'number'],
        'inviteCode' => ['require'],
        'idCard'     => ['require'],
        'dealPwd'    => ['require', 'length:6,18', 'alphaNum'],
        'reDealPwd'  => ['require', 'confirm:dealPwd'],
        'suffix'     => ['require'],
        'money'      => ['require', 'float', 'gt:0'],
        'betType'    => ['require', 'in:1,2'],
        'marketType' => ['require', 'in:1,2,3,4'],
        'dealTime'   => ['require', 'in:60'],
        'assetsType' => ['require', 'in:1,2'],
        'page'       => ['require', 'number', 'gt:0'],
        'size'       => ['require', 'number', 'gt:0'],
        'market'     => ['require', 'in:1,2,3,4'],
        'time'       => ['require', 'in:m,h,d,15m,30m'],
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名'    =>    '错误信息'
     *
     * @var array
     */
    protected $message = [
        'email.require'      => 'email_format_err',
        'email.alphaNum'     => 'email_format_err',
        'email.email'        => 'email_format_err',
        'name.require'       => 'name require',
        'name.length'        => 'name between',
        'name.alphaNum'      => 'name alphaNum',
        'idCard.require'     => 'id_card require',
        'password.require'   => 'password require',
        'password.length'    => 'password length',
        'password.alphaNum'  => 'password alphaNum',
        'rePassword.require' => 'rePassword require',
        'rePassword.confirm' => 'rePassword confirm',
        'code.require'       => 'msg_code_error',
        'code.number'        => 'msg_code_error',
        'inviteCode.require' => 'inviteCode require',
        'dealPwd.require'    => 'dealPwd require',
        'dealPwd.length'     => 'dealPwd length',
        'dealPwd.alphaNum'     => 'dealPwd alphaNum',
        'reDealPwd.confirm'  => 'reDealPwd confirm',
        'suffix.require'     => 'suffix require',
        'money.require'      => 'money require',
        'money.float'        => 'money float',
        'money.gt'           => 'money gt',
        'dealTime.require'   => 'dealTime require',
        'dealTime.in'        => 'dealTime in',
        'betType.require'    => 'betType require',
        'betType.in'         => 'betType in',
        'marketType.require' => 'marketType require',
        'marketType.in'      => 'marketType in',
        'assetsType.require' => 'assetsType require',
        'assetsType.in'      => 'assetsType in',
        'page.require'       => 'page require',
        'page.number'        => 'page number',
        'page.gt'            => 'page gt',
        'size.require'       => 'size require',
        'size.number'        => 'size number',
        'size.gt'            => 'size gt',
        'market.require'     => 'market require',
        'market.in'          => 'market in',
        'time.require'       => 'time require',
        'time.in'            => 'time in',
    ];

    //场景验证
    protected $scene = [
        //登陆场景
        'login'          => ['email', 'password'],
        //注册场景
        'register'       => ['email', 'password', 'rePassword', 'code', 'inviteCode'],
        //获取验证码场景
        'getCode'        => ['email'],
        //修改手机号场景
        'updateMobile'   => ['email', 'dealPwd'],
        //修改登陆密码
        'updateLoginPwd' => ['password', 'rePassword', 'code'],
        //找回登陆密码
        'findLoginPwd'   => ['email', 'password', 'rePassword', 'code'],
        //修改交易密码
        'updateDealPwd'  => ['dealPwd', 'reDealPwd', 'code'],
        //设置用户名
        'setUserName'    => ['name'],
        //check验证码
        'checkCode'      => ['email', 'suffix', 'code'],
        //实名认证
        'authentication' => ['name', 'idCard'],
        //下单
        'order'          => ['money', 'betType', 'marketType', 'dealTime', 'assetsType'],

        // 分页场景
        'paginate'       => ['page', 'size'],

        // 获取k线
        'geBrokenLine'   => ['market', 'time'],
    ];
}
